package com.gdones.bootserver.bus.station.controller;


import com.gdones.bootserver.bus.station.dto.Station;
import com.gdones.bootserver.bus.station.service.IStationService;
import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 岗位管理
 * @author GaoJingBo
 * @since 2023-04-07
 */
@RestController
@RequestMapping("/sys/station")
@Api(tags={"岗位管理"})
@Slf4j
public class StationController {

    @Resource(name = "stationServiceImpl")
    private IStationService stationService;

    /**
     * 岗位分页列表
     * @param station 岗位查询参数
     * @param page 分页参数
     * @return
     */
    @GetMapping("/pages")
    @ApiOperation("岗位分页列表")
    @MySysLog(modelName="岗位管理",methodDesc = "岗位分页列表",methodType = MySysLogOpration.GET)
    public MyResult getStationPage(Station station, MyPageBand page){
        log.info("--- 岗位管理：岗位分页列表");

        MyResult result = new MyResult();

        try{
            result = stationService.pages(station,page);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("岗位分页列表系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 添加-岗位
     * @param station 岗位数据
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加-岗位")
    @MySysLog(modelName="岗位管理",methodDesc = "添加",methodType = MySysLogOpration.POST)
    public MyResult addParam(@RequestBody Station station){
        log.info("--- 岗位管理：添加-岗位");

        MyResult result = new MyResult();

        try{
            result = stationService.add(station);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("添加-岗位系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 修改-岗位
     * @param station 岗位数据
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改-岗位")
    @MySysLog(modelName="岗位管理",methodDesc = "修改",methodType = MySysLogOpration.PUT)
    public MyResult updateParam(@RequestBody Station station){
        log.info("--- 岗位管理：修改-岗位");

        MyResult result = new MyResult();

        try{
            result = stationService.update(station);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("修改-岗位系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 删除-岗位
     * @param ids 可批量、单独删除的岗位id，逗号分隔
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除-岗位")
    @MySysLog(modelName="岗位管理",methodDesc = "删除",methodType = MySysLogOpration.DELETE)
    public MyResult updateParam(String ids){
        log.info("--- 岗位管理：删除-岗位");

        MyResult result = new MyResult();

        try{
            result = stationService.delete(ids);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("删除-岗位系统异常");
            result.setCode("9999");
        }

        return result;
    }

}
